#pragma once

#include "LeaderFollower.h"

#include <ace/Task.h>
#include <ace/Activation_Queue.h>
#include <ace/Method_Request.h>

class CPPXCORBA_API LF_ThreadPool :
    public ACE_Task_Base,
    public LeaderFollower
{
    class ExitRequest : public ACE_Method_Request
    {
    public:
        virtual int call (void){
            return -1;  // Cause exit.
        }
    };

    bool m_bShutdown;
    bool m_bRunning;
    ACE_Activation_Queue m_activation_queue_;

    static const size_t ScheduleTime = 10;
    static const size_t MinThreadNum = 10;
    static const size_t MaxThreadNum = 20;

public:
    LF_ThreadPool(void);
    ~LF_ThreadPool(void);

    virtual int svc(void);

    int start_stread_pool( void );
    int stop_thread_pool( void );
    int post_request( ACE_Method_Request *request );

    int get_queue_load(void){ return m_activation_queue_.method_count(); }
    int get_max_thread(void){ return MaxThreadNum; }
    int get_min_thread(void){ return MinThreadNum; }

private:
    int _fork_new_thread( void );
    int _post_exit_request(void);
};
